package umg.os.devices.filesystem;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;

import umg.os.devices.filesystem.basic.BasicFileSystem;
import umg.os.devices.filesystem.basic.BasicFileSystem.DataOversizedException;
import umg.os.devices.filesystem.basic.HDDHandler;
import umg.os.devices.filesystem.basic.HDDHandler.VolumeUnavailableException;
import umg.os.devices.filesystem.logical.File;
import umg.os.devices.filesystem.logical.LogicalFileSystem;

public class UMGFileSystem {
	
	private LogicalFileSystem lfs; 
	
	private UMGFileSystem(LogicalFileSystem lfs) {
		this.lfs = lfs;
	}

	public void cd(String path) throws NoSuchFileException {
		lfs.setWorkingDirectory(path);
	}
	
	public String getPrompt() {
		return lfs.getAbsolutePathFor(lfs.getWorkingDirectory().getId())+":$:";
	}
	
	public void mkdir(String path) throws IOException, VolumeUnavailableException, DataOversizedException {
		File newDirectory = lfs.getFile(path);
		lfs.createDirectory(newDirectory);
	}

	public void mkFil(String path) throws FileNotFoundException, IOException, VolumeUnavailableException, DataOversizedException {
		File newFile = lfs.getFile(path);
		lfs.createFile(newFile);
	}
	
	public File open(String path) throws FileNotFoundException, IOException, VolumeUnavailableException, DataOversizedException {
		return lfs.getFile(path);
	}
	
	public static UMGFileSystem mount(HDDHandler diskToMount) throws IOException, VolumeUnavailableException {
		return new UMGFileSystem(new LogicalFileSystem(new BasicFileSystem(diskToMount)));
	}
	
	public static UMGFileSystem mount(Path locationOfDiskToMount) throws IOException, VolumeUnavailableException {
		return UMGFileSystem.mount(new HDDHandler(locationOfDiskToMount));
	}
	
	public static void createNewVolume(Path locationOfNewDisk) throws DataOversizedException, IOException, VolumeUnavailableException {
		HDDHandler.createDisc(locationOfNewDisk);
		HDDHandler drive = new HDDHandler(locationOfNewDisk);
		BasicFileSystem.formatDisc(drive);
		BasicFileSystem bfs = new BasicFileSystem(drive);
		LogicalFileSystem.installSO(bfs);
		new LogicalFileSystem(bfs);
	}
	
}
